import '@babel/polyfill'
import Vue from 'vue'

// 主框架的东西 start
import '@/config'
import store from '@/store'
import keepAlive from '@/core/keepAlive'
// 主框架的东西 end

import 'ionicons-npm/css/ionicons.css' // 图标CSS资源
import 'ep-ui/theme/lib/ionicons3/ionicons3.min.css' // 新图标库，可选
import 'ep-ui/theme/lib/epui.min.css' // ep-ui原始样式
import epui from 'ep-ui'
import router from './routerChunk'
import App from './App.vue'

Vue.component('keep-alive', keepAlive)

// 动态引入组件
import chunkObj from './chunk-register'
for (let moudleName in chunkObj) {
  for (let chunkName in chunkObj[moudleName]) {
    let chunk = require('' + chunkObj[moudleName][chunkName].path)
    chunk.install &&
      chunk.install({
        chunkName,
        Vue,
        store
      })
    Vue.component(chunkName, chunk.cpt)
    // const requireAll = requireContext => requireContext.keys().map(requireContext)
    // const req = require.context('./svgs', false, /\.svg$/)
    // const iconMap = requireAll(req)
  }
}

// 引入ep-ui等
Vue.use(epui, {
  messagePlain: true
  // size: 'small'
})

global.chunkRouter = router

import { epEnv } from '@/common/vars.js'
import settings from '@/settings'
import Err404 from '@/views/404'
// #EPFC-epin-start
// epin css
// import '@easipass/epin-render-plus/lib/style/default.less'
// import '@easipass/epin-render-plus/lib/style/public.less'
// import '@easipass/epin-render-plus/lib/style/baseCss.css'
// EPin
if (settings.epin) {
  const EasipassEpin = require('@easipass/epin').default
  Vue.use(EasipassEpin, {
    epinConfig: {
      mode: epEnv.epinMode || 'remote',
      env: epEnv.epinEnv,
      url: epEnv.epinUrl,
      unpkgUrl: epEnv.unpkgHOST,
      appCode: epEnv.appCode,
      token: epEnv.token
    },
    router,
    store,
    Err404: Err404,
    newFront: true
  })
}

// import cookie from '@easipass/utils/cookie'
// import localStorage from '@easipass/utils/localStorage'
// // 处理cmtokenAc
// console.log('cookie set')
// let hashUrl = window.location.hash
// console.log(hashUrl)
// let urlParams = hashUrl.split('?')[1]
// if (urlParams) {
//   let keyValue = urlParams.split('&');
//   let paramsObj = {};
//   for (let i = 0; i < keyValue.length; i++) {
//     let item = keyValue[i].split('=');
//     let paramsKey = item[0];
//     paramsObj[paramsKey] = item[1] || '';
//   }
//   console.log(paramsObj)
//   if (paramsObj.hasOwnProperty('cmAuthCode')) {
//     let cmtokenAc = paramsObj['cmAuthCode']
//     console.log('chunk',cmtokenAc)
//     global.hasCmAuthCode = true
//     settings.headerAuthKey = 'Cm-Authorization-Ac'
//     settings.tokenName = 'Cm-Authorization-Ac'
//     cookie.setProcessCookie('cmtoken', cmtokenAc)
//     localStorage.setLocalStorage('cmtoken', cmtokenAc, 1)
//     store.dispatch('setToken', cmtokenAc)
//   }
// }

// #EPFC-epin-end
new Vue({
  router,
  store: store,
  render: h => h(App)
}).$mount('#app')
